public class MyQueen {

    static class ListNode {
        public int val;
        public ListNode prve;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }

    public ListNode first;
    public ListNode last;

    public int usesize = 0;

    public void offer(int p) {
        ListNode t = new ListNode(p);
        if (isEmpty()) {
            first = last = t;
        } else {
            last.next = t;
            t.prve = last;
            last = last.next;
        }
        usesize++;
    }

    public int poll() {
        if (isEmpty()) {
            return -1;
        }
        int p = first.val;
        first = first.next;
        if (first != null) {
            first.prve = null;
        }
        usesize--;
        return p;
    }

    public int peek() {
        if (isEmpty()) {
            return -1;
        }
        return first.val;
    }

    public boolean isEmpty() {
        return usesize == 0;
    }
}
